package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.fastjson.JSON;
import com.authine.cloudpivot.ext.dto.finance.AccountDto;
import com.authine.cloudpivot.ext.service.account.AccountService;
import com.authine.cloudpivot.ext.service.account.impl.AccountServiceImpl;
import com.authine.hermes.app.launcher.service.ApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.POST;
import javax.ws.rs.Path;


import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

@Path("AccountController")
@Slf4j
public class AccountController extends ApplicationService {
    public static AccountService accountService = new AccountServiceImpl();

    @Path("updateAccount")
    @POST
    @Operation(summary = "账户管理-更新账户信息",tags = CUSTOM_SERVICE)
    public SingleResponse<Boolean> updateAccount(AccountDto accountDto){
        log.info("================更新账户dto ={}", JSON.toJSONString(accountDto));
        if(accountDto.getId() == null){
            return SingleResponse.buildFailure("-1","账户ID不能为空");
        }
        if(accountDto.getAccount_balance() == null){
            return SingleResponse.buildFailure("-1","余额不能为空");
        }
        if(accountDto.getAvailable_limit() == null){
            return SingleResponse.buildFailure("-1","可用额度不能为空");
        }
        accountService.update(accountDto);
        return  SingleResponse.buildSuccess();
    }

    @Path("loadAccountById")
    @POST
    @Operation(summary = "通过ID获取结算账户账户信息",tags = CUSTOM_SERVICE)
    public AccountDto loadAccountById(AccountDto dto){
        return accountService.loadById(dto.getId());
    }


}
